package com.youmingxing.activity.selfInfo;

import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.View;
import android.widget.TextView;

import com.youmingxing.BuildConfig;
import com.youmingxing.R;
import com.youmingxing.activity.BaseActivity;
import com.youmingxing.network.HttpManager;

import java.util.List;


/**
 * Created by JHS on 2015/9/10
 * 关于页面
 */
public class AboutAppActivity extends BaseActivity {


    private TextView appVersionTv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        BaseSetContentView(R.layout.activity_aboutapp);
        initView();
    }

    private void initView() {
        setTopbarName(R.string.about_title);
        appVersionTv = (TextView) findViewById(R.id.about_appversion);
        appVersionTv.setText(getResources().getString(R.string.about_appversion) + BuildConfig.VERSION_NAME);
        if (BuildConfig.FLAVOR.equals("dev")){
            findViewById(R.id.mobile_icon).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    doubleClick();
                }
            });
        }
    }

    //test
    /**
     * 双击事件、多击事件
     */
    //存储时间的数组
    long[] mHits = new long[2];
    public void doubleClick() {
        // 双击事件响应
        /**
         * arraycopy,拷贝数组
         * src 要拷贝的源数组
         * srcPos 源数组开始拷贝的下标位置
         * dst 目标数组
         * dstPos 开始存放的下标位置
         * length 要拷贝的长度（元素的个数）
         *
         */
        //实现数组的移位操作，点击一次，左移一位，末尾补上当前开机时间（cpu的时间）
        System.arraycopy(mHits, 1, mHits, 0, mHits.length - 1);
        mHits[mHits.length - 1] = SystemClock.uptimeMillis();
        //双击事件的时间间隔500ms
        if (mHits[0] >= (SystemClock.uptimeMillis() - 500)) {
            //具体的操作
            //do
            if (HttpManager.BASE_URL.equals("https://t1.youmingxing.com/")){
                HttpManager.BASE_URL = "https://api.youmingxing.com/";
                showToast("Change to NORMAL");
            } else {
                HttpManager.BASE_URL = "https://t1.youmingxing.com/";
                showToast("Change to TEST");
            }
        }
    }

    //test over

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void startActivity(Intent intent) {
        if (intent.toString().contains("mailto")) { // Any way to judge that this is to sead an email
            PackageManager pm = getPackageManager();
            // The first Method
            List<ResolveInfo> activities = pm.queryIntentActivities(intent, 0);
            if (activities == null || activities.size() == 0) {
                showToast("您的手机未安装邮件");
                return;
            }
        }
        super.startActivity(intent);
    }
}